package com.mengfou.appserver.app;

import android.app.Activity;
import android.content.Context;

import java.lang.ref.WeakReference;

/**
 * @author 梦否 on 2024/1/5
 * @blog https://mengfou.blog.csdn.net/
 */
public enum AppGlobalContext {
    instance;

    private WeakReference<Context> contextWeakReference;
    private WeakReference<Activity> activityWeakReference;


    public Activity getTopActivity() {
        if(activityWeakReference != null) {
            return activityWeakReference.get();
        }
        return null;
    }

    public Context getApplicationContext() {
        if(contextWeakReference != null) {
            return contextWeakReference.get();
        }
        return null;
    }

    public void setTopActivity(Activity activity) {
        this.activityWeakReference = new WeakReference<>(activity);
    }

    public void setApplicationContext(Context context) {
        this.contextWeakReference = new WeakReference<>(context);
    }
}
